{extend name="base" /}
{block name="content"}
<div class="content">
    <div class="container-fluid">
        <!-- Page-Title -->
    <div class="row">
        <div class="col-12">
            <div class="page-title-box">
                <div class="page-title-right">
                    <ol class="breadcrumb m-0">
                        <li class="breadcrumb-item"><a href="{:url('index/index')}"><i class="fe-home"></i> 控制台</a></li>
                        <li class="breadcrumb-item"><a href="javascript: void(0);">管理员管理</a></li>
                        <li class="breadcrumb-item active">管理员列表</li>
                    </ol>
                </div>
                <h4 class="page-title"> <i class="fe-user-check"></i> 管理员管理</h4>
            </div>
        </div>
        <div class="col-lg-12">
            <div class="alert alert-success alert-dismissable">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button>
                <i class="mdi mdi-alert-circle-outline mr-2"></i>没有删除管理员操作，如需禁止登录请修改登录状态为【禁用】
            </div>  
            <div class="card-box">
                <div class="table-responsive">
                <a href="{:url('admin/add')}" class="btn btn-sm btn-success waves-effect waves-light float-right"><i class="mdi mdi-plus-circle"></i> 添加管理员</a>
                <h4 class="header-title mb-4">管理员列表</h4>
                    <div class="col-10 text-sm-center form-inline">
                        <form class="navbar-form form-inline" action="/admin/admin/index" method="get">
                        <div class="form-group mr-2">
                            <select id="demo-foo-filter-status" class="custom-select custom-select-sm" name="status">
                                <option value="">--登录状态--</option>
                                <option value="1" {if $Think.get.status == 1}selected{/if} >启用</option>
                                <option value="2" {if $Think.get.status == 2}selected{/if} >禁用</option>
                            </select>
                        </div>
                        <div class="form-group mr-2">
                            <select id="demo-foo-filter-status" class="custom-select custom-select-sm" name="role_id">
                                <option value="">--管理员角色--</option>
                                {foreach $role_list as $key => $val}
                                <option value="{$val.id}" {if $Think.get.status == 1}selected{/if} >{$val['role_name']}</option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="form-group">
                            <input id="demo-foo-search" type="text" value="{$Think.get.keywords}" placeholder="登录账号/姓名" class="form-control form-control-sm" name="keywords">
                        </div>
                        <div class="form-group">
                            <button type="submit" class="form-control form-control-sm btn-sm btn-success" style="cursor: pointer;margin-right: 10px;margin-left: 10px;"><i class="fe-search"></i> 搜索</button>
                        </div>
                        </form>
                    </div>
                    <br/>
                    <table class="tablesaw table table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>登录账号</th>
                                <th>姓名</th>
                                <th>添加日期</th>
                                <th>最后登录</th>
                                <th>状态</th>
                                <th>角色</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {empty name="$list"}
                            <tr>
                                <td colspan="8" id="colspanTbal">
                                    <span class="fe-alert-triangle"></span> 暂无数据～
                                </td>
                            </tr>
                            {/empty}
                            {foreach $list as $key => $val}
                            <tr>
                                <td>{$val.id}</td>
                                <td>{$val.username}</td>
                                <td>{$val.nick}</td>
                                <td>{$val.create_at}</td>
                                <td>{$val.end_time}</td>
                                <td>
                                    {switch name="$val.status" }
                                        {case value="2"}<span class="badge bg-soft-secondary text-secondary shadow-none">禁用</span>{/case}
                                        {case value="1"}<span class="badge bg-soft-success text-success shadow-none">启用</span>{/case}
                                    {/switch}
                                </td>
                                <td>{$val.role_name ? $val.role_name : '<span class="badge bg-soft-danger text-danger shadow-none">超级管理员</span>'}</td>
                                <td>
                                {if condition="$val.role_name"}
                                <a href="{:url('admin/edit', array('id' => $val['id']))}" class="badge badge-success"  data-toggle="tooltip" data-placement="top" data-original-title="编辑" style="float: none;"><i class="fe-edit"></i></a>
                                
                                <a href="javascript:;" onclick="del(this)" data-id="{$val.id}" class="badge badge-danger"  data-toggle="tooltip" data-placement="top" data-original-title="删除" style="float: none;"><i class="fe-trash-2"></i></a>

                                {/if}
                            </tr>
                            {/foreach}
                        </tbody>
                    </table>

                </div>
                <!--分页位置-->
                {$list->render()}
            </div>
        </div> <!-- end col -->

        
    </div>
    </div> <!-- container -->

</div> <!-- content -->
<script src="/static/layui/layui.js"></script>
<script>
    layui.use(['element', 'upload'], function () {
        element = layui.element;
        upload = layui.upload;
    })

    function del(e){
        var id = $(e).attr('data-id')
        layer.confirm('确认删除？', {
            btn: ['确定','取消'],
            title: '操作提示',
            icon: 7,
        }, function(){
            $.get('/admin/admin/admin_del',{id:id},function(res){
                if(res.code == 0){
                    layer.msg(res.message,{icon:1, shade: [0.2, '#ccc'], time:800});
                    // window.open(res.data);
                    $(e).parents("tr").remove();
                }else{
                    layer.msg(res.message,{icon:5, anim: 6});
                }
            },'json');
        });     
    }
</script>
{/block}